exports.checkLogin = (req, res, next) => {
    // console.log(req)
    if (req.session && req.session.user) {
        return next()
    }
    req.flash('error', '该页面需要登录后访问！')

    // 设置登录后的跳转 req.url /post/create
    return res.redirect(`/login?callback=${req.originalUrl}`)
        // return res.redirect(`/login?callback=${req._parsedOriginalUrl.path}`)
}


exports.checkNoLogin = (req, res, next) => {
    if (req.session && req.session.user) {
        req.flash('error', '该页面非登录用户才能访问！')
        return redirect('back')
    }
    return next()
}